//
//  HomeViewController.m
//  OCDome
//
//  Created by 李含文 on 2020/7/30.
//  Copyright © 2020 李含文. All rights reserved.
//

#import "HomeViewController.h"
#import "NSMutableParagraphStyle+WY_Extension.h"
#import "NSMutableAttributedString+WY_Extension.h"
#import "UILabel+HWTouch.h"
#import "UIView+HWCategory.h"
#import "HWDataRequest.h"
#import "HWTouchLabel.h"
#import "HWStability.h"

@interface HomeViewController ()<UITableViewDelegate, UITableViewDataSource>

/* <#name#> */
@property (nonatomic, strong) UITableView *tableView;

/* <#name#> */
@property (nonatomic, strong) NSArray<NSString *> *titles;

/// <#name#>
@property (nonatomic, strong) HWDispatchGroup *group;
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"首页";
    self.titles = @[@"返回手势/按钮点击拦截", @"底部弹出动画", @"星星控件", @"自定义Switch", @"多图浏览器", @"给view添加阴影", @"语言播报", @"Sorket服务器端", @"Sorket客服端",@"FMDB封装", @"加解密工具", @"图片缩放"];
//    self.view.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:self.tableView];
//    self.view.backgroundColor = UIColor.lightGrayColor;
    
    HWDispatchGroup *group = [HWDispatchGroup dispatchGroup];
//    self.group = group;
    [group addAsyncTask:^(HWDispatchGroup * _Nonnull group) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSLog(@"测试1");
            [group taskComplete];
        });
    }];
    
    [group addAsyncTask:^(HWDispatchGroup * _Nonnull group) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSLog(@"测试2");
            [group taskComplete];
        });
    }];
    [group groupNotify:^{
        NSLog(@"完成");
    }];
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = UIColor.clearColor;
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titles.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView hw_dequeueReusableCell:@"UITableViewCell" and:indexPath];
    cell.textLabel.text = self.titles[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *title = self.titles[indexPath.row];
    UIViewController *vc;
    if ([title isEqualToString:@"返回手势/按钮点击拦截"]) {
        [LoginViewController show:^{ }];
    } else if ([title isEqualToString:@"底部弹出动画"]) {
        vc = [NSClassFromString(@"PopoAnimationViewController") new];
        [self presentViewController:vc animated:YES completion:^{}];
        return;
    } else if ([title isEqualToString:@"星星控件"]) {
        vc = [NSClassFromString(@"NewMidViewController") new];
    } else if ([title isEqualToString:@"自定义Switch"]) {
        vc = [NSClassFromString(@"SwitchViewController") new];
    } else if ([title isEqualToString:@"多图浏览器"]) {
        vc = [NSClassFromString(@"YCCollectionViewController") new];
    } else if ([title isEqualToString:@"给view添加阴影"]) {
        vc = [NSClassFromString(@"HWShadowViewController") new];
    } else if ([title isEqualToString:@"语言播报"]) {
        vc = [NSClassFromString(@"SpeechViewController") new];
    } else if ([title isEqualToString:@"Sorket服务器端"]) {
        vc = [NSClassFromString(@"GCDSocketServerViewController") new];
    } else if ([title isEqualToString:@"Sorket客服端"]) {
        vc = [NSClassFromString(@"GCDSocketClientViewController") new];
    } else if ([title isEqualToString:@"FMDB封装"]) {
        vc = [NSClassFromString(@"FMDBViewController") new];
    } else if ([title isEqualToString:@"加解密工具"]) {
        vc = [NSClassFromString(@"EncryptionViewController") new];
    } else if ([title isEqualToString:@"图片缩放"]) {
        vc = [NSClassFromString(@"ZoomingViewController") new];
    }
    
    if (!vc) return;
    vc.title = title;
    [self.navigationController pushViewController:vc animated:YES];
}




@end
